package org.jason.common.satoken.exception;

import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.exception.NotPermissionException;
import cn.dev33.satoken.exception.NotRoleException;
import org.jason.model.common.dtos.ResponseResult;
import org.jason.model.common.enums.HttpCodeEnum;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Order(Ordered.HIGHEST_PRECEDENCE)
public class AuthExceptionHandler {
    /**
     * 未登录异常
     *
     * @param e
     * @return
     */
    @ExceptionHandler(NotLoginException.class)
    public ResponseResult handleException(NotLoginException e) {
        return ResponseResult.get(HttpCodeEnum.NEED_LOGIN);
    }

    /**
     * 缺少权限异常
     *
     * @param e
     * @return
     */
    @ExceptionHandler({NotPermissionException.class, NotRoleException.class})
    public ResponseResult handleException(Exception e) {
        return ResponseResult.get(HttpCodeEnum.NO_OPERATOR_AUTH);
    }
}
